// pages/direct/direct.js
var app = getApp()
Page({
  data: {    
    current: 1    
  },
  onLoad: function (options) {
    // 页面初始化 options为页面跳转所带来的参数      
    var that = this;
    console.log(options);
    that.setData({
      directId: options.id
    });    
   // console.log(this);
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight,
          imageUrl: app.globalData.imageUrl
        })
      }
    })  
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示  
    getBackData(this)//获取普通商品      
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭

  },  
  toDetail: function (e) {//跳转到详情页面
    wx.navigateTo({
      url: '/pages/directDetail/directDetail?id=' + e.target.dataset.id,
    })
  }
})


function getBackData(that, classifys) {//从后台获取直营普通商品
  if (!classifys) {
    classifys = that.data.current
    that.setData({//储存当前页已经加载过的信息
      currentPage1: true
    })
  } else {
    if (classifys == 1) {
      that.setData({//储存当前页已经加载过的信息
        currentPage1: true
      })
    } else if (classifys == 2) {
      that.setData({//储存当前页已经加载过的信息
        currentPage2: true
      })
    } else if (classifys == 3) {
      that.setData({//储存当前页已经加载过的信息
        currentPage3: true
      })
    }
  }
  // console.log(classifys)
  wx.request({
    url: app.globalData.allUrl + "/directAction/getDirectProduct",
    data: {
      pageNum: 1,
      pageCount: 1000,
      directId: that.data.directId,
     
     // classify: 7,
      putaway: 1
      // type:0//加载普通商品0，由于前期商品少，故注释
    },
    method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function (res) {
      //console.log(res.data);
      if (res.data && res.data.list.length > 0) {
        if (classifys == 1) {
          that.setData({
            DirectProduct1: res.data.list,
          })
        } else if (classifys == 2) {
          that.setData({
            DirectProduct2: res.data.list,
          })
        } else if (classifys == 3) {          
          that.setData({
            DirectProduct3: res.data.list
          })
        }
      }
    }
  })
}




